<?
require_once('classes/sql_wtc.php');

$db = new MySQL_Class();
$db->Create();
$i=0;
$t=strtotime('2004-11-01');
$sql="select * from pro_basic_temp where subsub<>'' order by issue asc";
$db->Query($sql);
if ($res=$db->result) {
	while ($rec=mysql_fetch_object($res)){
		$sql="select a.id,a.parent from pro_category as a,pro_category as b,pro_category as c where a.parent=b.id and b.parent=c.id and a.name='".$rec->subsub."' and b.name='".$rec->sub."' and c.name='".$rec->main."'";
		$db->Query($sql);
		//echo $sql."<br>";
		$r=mysql_fetch_object($db->result);
		$sql="insert into pro_basic (code,name,brand,description,remark,price_euro,category,parent_category,auth,mark_new,publish,weight,reorder,stock,issuedate,sn_cn,updatetime)
		values (
		'".$rec->code."',
		'".$rec->name."',
		'".$rec->brand."',
		'',
		'".$rec->remark."',
		".$rec->price.",
		'".$r->id."',
		'".$r->parent."',
		".$rec->auth.",
		'".$rec->mark_new."',
		".$rec->publish.",
		".$rec->weight.",
		0,
		".$rec->stock.",
		".(strtotime($rec->issue)).",
		'".$rec->sn_c."',
		".$t."
		)";
		$db->Query($sql);
		if ($db->result)
		 echo $r->parent.' - '.$r->id.'<br><br>';
			else echo "<font color=red>FAILD!</font><br>";
		$i++;
	}
}

$sql="select * from pro_basic_temp where subsub='' and sub<>'' order by issue asc";
$db->Query($sql);
if ($res=$db->result) {
	while ($rec=mysql_fetch_object($res)){
		$sql="select b.id,b.parent from pro_category as b,pro_category as c where  b.parent=c.id and b.name='".$rec->sub."' and c.name='".$rec->main."'";
		$db->Query($sql);
		//echo $sql."<br>";
		$r=mysql_fetch_object($db->result);
		$sql="insert into pro_basic (code,name,brand,description,remark,price_euro,category,parent_category,auth,mark_new,publish,weight,reorder,stock,issuedate,sn_cn,updatetime)
		values (
		'".$rec->code."',
		'".addslashes($rec->name)."',
		'".$rec->brand."',
		'',
		'".$rec->remark."',
		".$rec->price.",
		'".$r->id."',
		'".$r->parent."',
		".$rec->auth.",
		'".$rec->mark_new."',
		".$rec->publish.",
		".$rec->weight.",
		0,
		".$rec->stock.",
		".(strtotime($rec->issue)).",
		'".$rec->sn_c."',
		".$t."
		)";
		$db->Query($sql);
		if ($db->result) 
		echo $r->parent.' - '.$r->id.'<br><br>';
			else echo "<font color=red>FAILD!</font><br>";
		$i++;
	}
}
echo $i;
?>